package com.voicechat.firstmet.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseAdapter;
import com.voicechat.firstmet.bean.RecordListBean;
import com.voicechat.firstmet.utils.Utils;

import java.text.ParseException;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.adapter
 * @ClassName: IncomeRecordAdapter
 * @Description: 充值记录adapter
 * @Author: ljp
 * @CreateDate: 2018/10/11 10:01
 * @Version: 1.0
 */
public class RechargeRecordAdapter extends BaseAdapter<RecordListBean.PageBean.ListBean> {
    private List<RecordListBean.PageBean.ListBean> tlist;
    /**
     * @param context activity_imessage
     * @param tlist   集合
     * @param mLayout 主布局
     */
    public RechargeRecordAdapter(Context context, List<RecordListBean.PageBean.ListBean> tlist, int mLayout) {
        super(context, tlist, mLayout);
        this.tlist = tlist;
    }

    @Override
    protected RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return null;
    }

    @Override
    protected RecyclerView.ViewHolder getItemViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    protected RecyclerView.ViewHolder getFooterViewHolder(View view) {
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        if(viewHolder instanceof ViewHolder){
            RecordListBean.PageBean.ListBean listBean = tlist.get(position);
            ((ViewHolder) viewHolder).tvMoneySum.setText(listBean.getGold()+"");

            String format = "yyyy-MM-dd HH:mm";
            try {
                String s = Utils.dateToString(Utils.stringToDate(listBean.getCreateDate(), format), format);
                ((ViewHolder) viewHolder).tvRechargeData.setText(s);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if(listBean.getType() .equals("0") ){
                ((ViewHolder) viewHolder).tvState.setTextColor(context.getResources().getColor(R.color.color55DC9D));
                ((ViewHolder) viewHolder).tvState.setText("成功");
            }else {
                ((ViewHolder) viewHolder).tvState.setTextColor(context.getResources().getColor(R.color.colorFF3B5E));
                ((ViewHolder) viewHolder).tvState.setText("失败");
            }

        }
    }

    class ViewHolder extends BaseViewHolder{
        @BindView(R.id.tv_recharge_data)
        TextView tvRechargeData;
        @BindView(R.id.tv_money_sum)
        TextView tvMoneySum;
        @BindView(R.id.tv_state)
        TextView tvState;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
